package lessons6;

import java.util.Properties;
import java.util.Set;

/**
 * System 类常用方法
 */
public class lessons6_3 {
    public static void main(String[] args) {
        System.out.println("\nSystem类常用方法:");

        timeTest();
        //copy();
        //getSysMsg();
    }

    /**
     * 系统时间戳演示
     */
    static public void timeTest()
    {
        long time1 = System.currentTimeMillis();
        System.out.println("\n系统时间戳演示:");
        System.out.println("循环执行前时间:"+time1);
        for(int i=0;i<900000;i++){}
        long time2 = System.currentTimeMillis();
        System.out.println("循环执行后时间:"+time2);
        System.out.println("循环执行时间:"+(time2-time1)+" ms ");
        System.out.println();
    }

    /**
     * 系统拷贝接口
     */
    static public void copy()
    {
        System.out.println("\n系统拷贝接口演示:");

        int[] datas1 = {1,2,3,4,5,6,7,8,9};
        int[] datas2 = {11,12,13,14,15,16,17,18,19};

        //调用系统接口 
        System.arraycopy(datas1, 1, datas2, 3, 2);

        System.out.println("datas1数据:"+showInts(datas1));
        System.out.println("datas2数据:"+showInts(datas2));

        //这是否是拷贝数据的方式
        int[] datas3 = datas1;
        System.out.println("datas3数据:"+showInts(datas3));

        //这是否是拷贝数据的方式
        int[] datas4 = new int[datas1.length];
        for(int i=0;i<datas1.length;i++)
        {
            datas4[i]=datas1[i];
        }
        System.out.println("datas4数据:"+showInts(datas4));

        datas1[4]=100;
        System.out.println("datas1[4]=100");
        System.out.println("datas3数据:"+showInts(datas3));
        System.out.println("datas4数据:"+showInts(datas4));

        System.out.println();
    }

    static private String showInts(int[] datas)
    {
        String log="{ ";
        for(int i=0;i<datas.length;i++)
            log+=datas[i]+", ";
        log+="}";
        return log;
    }
    /**
     * 获取系统属性
     */
    static public void getSysMsg()
    {
        System.out.println("\n获取系统属性:");
        Properties data = System.getProperties();
        //System.out.println(data);
        Set<String> keynames = data.stringPropertyNames();
        for(String key:keynames)
        {
            System.out.println(key+" --> "+System.getProperty(key));
        }
        System.out.println();
    }
}
